| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var assert = require('chai').assert, |
||
| 4 | describe('OnlineAccount', function(){ |
||
| 5 | |||
| 6 | it('Create plain', function(){ |
||
| 7 | assert.instanceOf(new GedcomX.OnlineAccount(), GedcomX.OnlineAccount, 'An instance of OnlineAccount is not returned when calling the constructor with new.'); |
||
| 8 | assert.instanceOf(GedcomX.OnlineAccount(), GedcomX.OnlineAccount, 'An instance of OnlineAccount is not returned when calling the constructor without new.'); |
||
| 9 | }); |
||
| 10 | |||
| 11 | it('Create with JSON', function(){ |
||
| 12 | var account = GedcomX.OnlineAccount({ |
||
| 13 | accountName: 'jimbo', |
||
| 14 | serviceHomepage: { |
||
| 15 | resource: 'http://service/home' |
||
| 16 | } |
||
| 17 | }); |
||
| 18 | assert.equal(account.getAccountName(), 'jimbo'); |
||
| 19 | assert.equal(account.getServiceHomepage().getResource(), 'http://service/home'); |
||
| 20 | }); |
||
| 21 | |||
| 22 | it('Create with mixed data', function(){ |
||
| 23 | var account = GedcomX.OnlineAccount({ |
||
| 24 | accountName: 'jimbo', |
||
| 25 | serviceHomepage: GedcomX.ResourceReference({ |
||
| 26 | resource: 'http://service/home' |
||
| 27 | }) |
||
| 28 | }); |
||
| 29 | assert.equal(account.getAccountName(), 'jimbo'); |
||
| 30 | assert.equal(account.getServiceHomepage().getResource(), 'http://service/home'); |
||
| 31 | }); |
||
| 32 | |||
| 33 | it('Build', function(){ |
||
| 34 | var account = GedcomX.OnlineAccount() |
||
| 35 | .setAccountName('jimbo') |
||
| 36 | .setServiceHomepage(GedcomX.ResourceReference().setResource('http://service/home')); |
||
| 37 | assert.equal(account.getAccountName(), 'jimbo'); |
||
| 38 | assert.equal(account.getServiceHomepage().getResource(), 'http://service/home'); |
||
| 39 | }); |
||
| 40 | |||
| 41 | it('toJSON', function(){ |
||
| 42 | var data = { |
||
| 43 | accountName: 'jimbo', |
||
| 44 | serviceHomepage: { |
||
| 45 | resource: 'http://service/home' |
||
| 46 | } |
||
| 47 | }, account = GedcomX.OnlineAccount(data); |
||
| 48 | assert.deepEqual(account.toJSON(), data); |
||
| 49 | }); |
||
| 50 | |||
| 51 | it('constructor does not copy instances', function(){ |
||
| 52 | var obj1 = GedcomX.OnlineAccount(); |
||
| 53 | var obj2 = GedcomX.OnlineAccount(obj1); |
||
| 54 | assert.strictEqual(obj1, obj2); |
||
| 55 | }); |
||
| 56 | |||
| 57 | }); |